

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>scitools.easyviz.gnuplot_ &mdash; SciTools 0.9.0 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '0.9.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="SciTools 0.9.0 documentation" href="../../../index.html" />
    <link rel="up" title="Module code" href="../../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for scitools.easyviz.gnuplot_</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This backend uses the Gnuplot plotting program together with the</span>
<span class="sd">Gnuplot.py Python module. One can specify this backend by</span>

<span class="sd">  python somefile.py --SCITOOLS_easyviz_backend gnuplot</span>

<span class="sd">or one can specify the backend in the SciTools configuration file</span>
<span class="sd">scitools.cfg under the [easyviz] section</span>

<span class="sd">  [easyviz]</span>
<span class="sd">  backend = gnuplot</span>

<span class="sd">and then</span>

<span class="sd">  from scitools.std import *</span>

<span class="sd">or if just easyviz is needed</span>

<span class="sd">  from scitools.easyviz import *</span>

<span class="sd">REQUIREMENTS:</span>

<span class="sd">Gnuplot &gt;= 4.0</span>
<span class="sd">Gnuplot.py</span>

<span class="sd">Tip:</span>

<span class="sd">  To close a figure window, press &lt;q&gt; when active</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">division</span>

<span class="kn">from</span> <span class="nn">common</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">scitools.numpyutils</span> <span class="kn">import</span> <span class="n">ones</span><span class="p">,</span> <span class="n">ravel</span><span class="p">,</span> <span class="n">shape</span><span class="p">,</span> <span class="n">newaxis</span><span class="p">,</span> <span class="n">rank</span><span class="p">,</span> <span class="n">transpose</span><span class="p">,</span> \
     <span class="n">linspace</span><span class="p">,</span> <span class="n">floor</span><span class="p">,</span> <span class="n">array</span>
<span class="kn">from</span> <span class="nn">scitools.globaldata</span> <span class="kn">import</span> <span class="n">DEBUG</span><span class="p">,</span> <span class="n">VERBOSE</span>
<span class="kn">from</span> <span class="nn">scitools.misc</span> <span class="kn">import</span> <span class="n">test_if_module_exists</span> <span class="p">,</span> <span class="n">system</span>
<span class="kn">from</span> <span class="nn">misc</span> <span class="kn">import</span> <span class="n">arrayconverter</span><span class="p">,</span> <span class="n">_update_from_config_file</span><span class="p">,</span> <span class="n">_check_type</span>

<span class="n">test_if_module_exists</span><span class="p">(</span><span class="s">&#39;Gnuplot&#39;</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">&#39;You need to install the Gnuplot.py package.&#39;</span><span class="p">,</span> <span class="n">abort</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">Gnuplot</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">operator</span>
<span class="kn">import</span> <span class="nn">string</span>
<span class="kn">import</span> <span class="nn">time</span>

<span class="c"># Update Gnuplot.GnuplotOpts according to scitools.cfg</span>
<span class="n">_update_from_config_file</span><span class="p">(</span><span class="n">Gnuplot</span><span class="o">.</span><span class="n">GnuplotOpts</span><span class="o">.</span><span class="n">__dict__</span><span class="p">,</span> <span class="n">section</span><span class="o">=</span><span class="s">&#39;gnuplot&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_check_terminal</span><span class="p">(</span><span class="n">term</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Return True if the given terminal work with Gnuplot, otherwise False.&quot;&quot;&quot;</span>
    <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">suffix</span><span class="o">=</span><span class="s">&#39;.gnuplot&#39;</span><span class="p">),</span> <span class="s">&#39;w&#39;</span><span class="p">)</span>
    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;set term </span><span class="si">%s</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">term</span><span class="p">)</span>
    <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
    <span class="n">cmd</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s"> &lt; </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">Gnuplot</span><span class="o">.</span><span class="n">GnuplotOpts</span><span class="o">.</span><span class="n">gnuplot_command</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
    <span class="n">failure</span><span class="p">,</span> <span class="n">output</span> <span class="o">=</span> <span class="n">system</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">failure_handling</span><span class="o">=</span><span class="s">&#39;silent&#39;</span><span class="p">)</span>
    <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
    <span class="k">return</span> <span class="ow">not</span> <span class="n">failure</span>

<span class="k">def</span> <span class="nf">_check_terminals</span><span class="p">(</span><span class="n">terms</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Check if the default terminal (Gnuplot.GnuplotOpts.default_term)</span>
<span class="sd">    work with Gnuplot. If not, try any of the terminals given in terms.</span>
<span class="sd">    Change the default terminal as necessary. Gnuplot will fail later if</span>
<span class="sd">    a working terminal can&#39;t be found.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_check_type</span><span class="p">(</span><span class="n">terms</span><span class="p">,</span> <span class="s">&#39;terms&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span>
    <span class="n">working_term</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">default_term</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">GnuplotOpts</span><span class="o">.</span><span class="n">default_term</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">terms</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">default_term</span> <span class="o">!=</span> <span class="n">terms</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
        <span class="n">terms</span> <span class="o">=</span> <span class="p">[</span><span class="n">default_term</span><span class="p">]</span> <span class="o">+</span> <span class="n">terms</span>
    <span class="k">for</span> <span class="n">term</span> <span class="ow">in</span> <span class="n">terms</span><span class="p">:</span>
        <span class="n">term_ok</span> <span class="o">=</span> <span class="n">_check_terminal</span><span class="p">(</span><span class="n">term</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">term_ok</span><span class="p">:</span>
            <span class="n">working_term</span> <span class="o">=</span> <span class="n">term</span>
            <span class="k">break</span>
    <span class="k">if</span> <span class="n">working_term</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">working_term</span> <span class="o">==</span> <span class="n">default_term</span><span class="p">:</span>
            <span class="c"># Gnuplot is built with the chosen terminal and it seems to be</span>
            <span class="c"># working so we don&#39;t need to do anything.</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">Gnuplot</span><span class="o">.</span><span class="n">GnuplotOpts</span><span class="o">.</span><span class="n">default_term</span> <span class="o">=</span> <span class="n">working_term</span>
            <span class="k">if</span> <span class="n">VERBOSE</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;Note: Default terminal for Gnuplot changed from &quot;</span> \
                      <span class="s">&quot;</span><span class="si">%s</span><span class="s"> to </span><span class="si">%s</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">default_term</span><span class="p">,</span> <span class="n">working_term</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c"># no working terminals found, will probably fail later</span>
        <span class="k">print</span> <span class="s">&quot;Warning: Unable to find a working terminal for use with </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> \
              <span class="n">Gnuplot</span><span class="o">.</span><span class="n">GnuplotOpts</span><span class="o">.</span><span class="n">gnuplot_command</span>

<span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span> <span class="o">==</span> <span class="s">&quot;darwin&quot;</span><span class="p">:</span>
    <span class="n">_check_terminals</span><span class="p">([</span><span class="s">&#39;aqua&#39;</span><span class="p">,</span> <span class="s">&#39;wxt&#39;</span><span class="p">,</span> <span class="s">&#39;x11&#39;</span><span class="p">])</span>

<span class="n">_gnuplotpy_major</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">__version__</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">_gnuplotpy_minor</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">__version__</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="k">if</span> <span class="n">_gnuplotpy_major</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">_gnuplotpy_minor</span> <span class="o">&lt;=</span> <span class="mi">7</span><span class="p">:</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">uname</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;x86_64&#39;</span><span class="p">:</span>
        <span class="c"># Gnuplot.py &lt;= 1.7 only supports Numeric (not NumPy) and Numeric</span>
        <span class="c"># does not work on 64 bits platform.</span>
        <span class="k">print</span> <span class="p">(</span><span class="s">&quot;Warning: Gnuplot.py version </span><span class="si">%s</span><span class="s"> is not support on 64 bits &quot;</span> \
               <span class="s">&quot;platform. Please upgrade to Gnuplot.py 1.8 or newer.&quot;</span><span class="p">)</span> <span class="o">%</span> \
               <span class="n">Gnuplot</span><span class="o">.</span><span class="n">__version__</span>
<span class="k">else</span><span class="p">:</span>
    <span class="c"># The arrayconverter function is only necessary for Gnuplot.py &lt;= 1.7:</span>
<div class="viewcode-block" id="arrayconverter"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.arrayconverter">[docs]</a>    <span class="k">def</span> <span class="nf">arrayconverter</span><span class="p">(</span><span class="n">a</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">a</span>
</div>
<div class="viewcode-block" id="get_gnuplot_version"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.get_gnuplot_version">[docs]</a><span class="k">def</span> <span class="nf">get_gnuplot_version</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return Gnuplot version used in Gnuplot.py.&quot;&quot;&quot;</span>
    <span class="n">f</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">popen</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> --version&#39;</span> <span class="o">%</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">GnuplotOpts</span><span class="o">.</span><span class="n">gnuplot_command</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>

<span class="c"># This function is taken from utils.py in Gnuplot.py and modified to fix</span>
<span class="c"># the problem with this message when plotting contours:</span>
<span class="c">#</span>
<span class="c">#   Notice: Cannot contour non grid data. Please use &quot;set dgrid3d&quot;</span>
<span class="c">#</span></div>
<div class="viewcode-block" id="write_array"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.write_array">[docs]</a><span class="k">def</span> <span class="nf">write_array</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span>
                <span class="n">item_sep</span><span class="o">=</span><span class="s">&#39; &#39;</span><span class="p">,</span>
                <span class="n">nest_prefix</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">nest_suffix</span><span class="o">=</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">nest_sep</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Write an array of arbitrary dimension to a file.</span>

<span class="sd">    A general recursive array writer.  The last four parameters allow</span>
<span class="sd">    a great deal of freedom in choosing the output format of the</span>
<span class="sd">    array.  The defaults for those parameters give output that is</span>
<span class="sd">    gnuplot-readable.  But using &#39;(&quot;,&quot;, &quot;{&quot;, &quot;}&quot;, &quot;,\n&quot;)&#39; would output</span>
<span class="sd">    an array in a format that Mathematica could read.  &#39;item_sep&#39;</span>
<span class="sd">    should not contain &#39;%&#39; (or if it does, it should be escaped to</span>
<span class="sd">    &#39;%%&#39;) since it is put into a format string.</span>

<span class="sd">    The default 2-d file organization::</span>

<span class="sd">        set[0,0] set[0,1] ...</span>
<span class="sd">        set[1,0] set[1,1] ...</span>

<span class="sd">    The 3-d format::</span>

<span class="sd">        set[0,0,0] set[0,0,1] ...</span>
<span class="sd">        set[0,1,0] set[0,1,1] ...</span>

<span class="sd">        set[1,0,0] set[1,0,1] ...</span>
<span class="sd">        set[1,1,0] set[1,1,1] ...</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
        <span class="p">(</span><span class="n">columns</span><span class="p">,)</span> <span class="o">=</span> <span class="nb">set</span><span class="o">.</span><span class="n">shape</span>
        <span class="k">assert</span> <span class="n">columns</span> <span class="o">&gt;</span> <span class="mi">0</span>
        <span class="n">fmt</span> <span class="o">=</span> <span class="n">string</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="n">columns</span><span class="p">,</span> <span class="n">item_sep</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_prefix</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">fmt</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="nb">set</span><span class="o">.</span><span class="n">tolist</span><span class="p">()))</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_suffix</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
        <span class="c"># This case could be done with recursion, but `unroll&#39; for</span>
        <span class="c"># efficiency.</span>
        <span class="p">(</span><span class="n">points</span><span class="p">,</span> <span class="n">columns</span><span class="p">)</span> <span class="o">=</span> <span class="nb">set</span><span class="o">.</span><span class="n">shape</span>
        <span class="k">assert</span> <span class="n">points</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">columns</span> <span class="o">&gt;</span> <span class="mi">0</span>
        <span class="n">fmt</span> <span class="o">=</span> <span class="n">string</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="n">columns</span><span class="p">,</span> <span class="n">item_sep</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_prefix</span> <span class="o">+</span> <span class="n">nest_prefix</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">fmt</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="nb">set</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()))</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_suffix</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">point</span> <span class="ow">in</span> <span class="nb">set</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_sep</span> <span class="o">+</span> <span class="n">nest_prefix</span><span class="p">)</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">fmt</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">point</span><span class="o">.</span><span class="n">tolist</span><span class="p">()))</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_suffix</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_suffix</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c"># Use recursion for three or more dimensions:</span>
        <span class="k">assert</span> <span class="nb">set</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span>
        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_prefix</span><span class="p">)</span>
        <span class="n">write_array</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="nb">set</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                    <span class="n">item_sep</span><span class="p">,</span> <span class="n">nest_prefix</span><span class="p">,</span> <span class="n">nest_suffix</span><span class="p">,</span> <span class="n">nest_sep</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">subset</span> <span class="ow">in</span> <span class="nb">set</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">nest_sep</span><span class="p">)</span>
            <span class="n">write_array</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">subset</span><span class="p">,</span>
                        <span class="n">item_sep</span><span class="p">,</span> <span class="n">nest_prefix</span><span class="p">,</span> <span class="n">nest_suffix</span><span class="p">,</span> <span class="n">nest_sep</span><span class="p">)</span>
        <span class="c"># Here is the fix: We comment out the next line so that we have</span>
        <span class="c"># only one newline character at the end of the temporary files:</span>
        <span class="c">#f.write(nest_suffix)</span>
</div>
<span class="n">Gnuplot</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">write_array</span> <span class="o">=</span> <span class="n">write_array</span>

<span class="c"># Change the order in which to cycle through line colors when plotting multiple</span>
<span class="c"># lines with the plot (or plot3) command. In Gnuplot we start with red since</span>
<span class="c"># this gives a solid line in black and white hardcopies:</span>
<span class="n">Axis</span><span class="o">.</span><span class="n">_local_prop</span><span class="p">[</span><span class="s">&#39;colororder&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;r b g c m y&#39;</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>

<div class="viewcode-block" id="GnuplotBackend"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend">[docs]</a><span class="k">class</span> <span class="nc">GnuplotBackend</span><span class="p">(</span><span class="n">BaseClass</span><span class="p">):</span>
<div class="viewcode-block" id="GnuplotBackend.__init__"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">BaseClass</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span>
</div>
    <span class="k">def</span> <span class="nf">_init</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Perform initialization that is special for this backend.&quot;&quot;&quot;</span>

        <span class="c"># Necessary to add a Gnuplot Session as _g to the Figure instance.</span>
        <span class="c"># self._g will now point to the correct instance saved as _g in</span>
        <span class="c"># curfig.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;curfig&#39;</span><span class="p">))</span>

        <span class="c"># conversion tables for format strings:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_markers</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span><span class="c"># no marker</span>
            <span class="s">&#39;.&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>  <span class="c"># dot</span>
            <span class="s">&#39;o&#39;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span>  <span class="c"># circle</span>
            <span class="s">&#39;x&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>  <span class="c"># cross</span>
            <span class="s">&#39;+&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>  <span class="c"># plus sign</span>
            <span class="s">&#39;*&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>  <span class="c"># asterisk</span>
            <span class="s">&#39;s&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>  <span class="c"># square</span>
            <span class="s">&#39;d&#39;</span><span class="p">:</span> <span class="mi">12</span><span class="p">,</span> <span class="c"># diamond</span>
            <span class="s">&#39;^&#39;</span><span class="p">:</span> <span class="mi">8</span><span class="p">,</span>  <span class="c"># triangle (up)</span>
            <span class="s">&#39;v&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="c"># triangle (down)</span>
            <span class="s">&#39;&lt;&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="c"># triangle (left) --&gt; (down)</span>
            <span class="s">&#39;&gt;&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="c"># triangle (right) --&gt; (down)</span>
            <span class="s">&#39;p&#39;</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span>  <span class="c"># pentagram --&gt; square</span>
            <span class="s">&#39;h&#39;</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span>  <span class="c"># hexagram --&gt; square</span>
            <span class="p">}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;&#39;</span> <span class="p">:</span> <span class="mi">1</span><span class="p">,</span>  <span class="c"># no color --&gt; red (gives solid line)</span>
            <span class="s">&#39;r&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>  <span class="c"># red</span>
            <span class="s">&#39;g&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>  <span class="c"># green</span>
            <span class="s">&#39;b&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>  <span class="c"># blue</span>
            <span class="s">&#39;c&#39;</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span>  <span class="c"># cyan --&gt; aqua</span>
            <span class="s">&#39;m&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>  <span class="c"># magenta --&gt; purple</span>
            <span class="s">&#39;y&#39;</span><span class="p">:</span> <span class="mi">7</span><span class="p">,</span>  <span class="c"># yellow --&gt; orange</span>
            <span class="s">&#39;k&#39;</span><span class="p">:</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="c"># black</span>
            <span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="mi">7</span><span class="p">,</span>  <span class="c"># white --&gt; orange</span>
            <span class="p">}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_line_styles</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>       <span class="c"># no line --&gt; point</span>
            <span class="s">&#39;-&#39;</span><span class="p">:</span> <span class="s">&#39;lines&#39;</span><span class="p">,</span>   <span class="c"># solid line</span>
            <span class="s">&#39;:&#39;</span><span class="p">:</span> <span class="s">&#39;lines&#39;</span><span class="p">,</span>   <span class="c"># dotted line --&gt; solid line</span>
            <span class="s">&#39;-.&#39;</span><span class="p">:</span> <span class="s">&#39;lines&#39;</span><span class="p">,</span>  <span class="c"># dash-dot line --&gt; solid line</span>
            <span class="s">&#39;--&#39;</span><span class="p">:</span> <span class="s">&#39;lines&#39;</span><span class="p">,</span>  <span class="c"># dashed line --&gt; solid line</span>
            <span class="p">}</span>

        <span class="c"># convert table for colorbar location:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_colorbar_locations</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;North&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;horizontal&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">2</span><span class="p">,</span><span class="o">.</span><span class="mi">74</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">,</span><span class="o">.</span><span class="mo">04</span><span class="p">),</span>
            <span class="s">&#39;South&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;horizontal&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">2</span><span class="p">,</span><span class="o">.</span><span class="mi">26</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">,</span><span class="o">.</span><span class="mo">04</span><span class="p">),</span>
            <span class="s">&#39;East&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;vertical&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">76</span><span class="p">,</span><span class="o">.</span><span class="mi">21</span><span class="p">,</span><span class="o">.</span><span class="mo">03</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">),</span>
            <span class="s">&#39;West&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;vertical&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">21</span><span class="p">,</span><span class="o">.</span><span class="mi">21</span><span class="p">,</span><span class="o">.</span><span class="mo">03</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">),</span>
            <span class="s">&#39;NorthOutside&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;horizontal&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">2</span><span class="p">,</span><span class="o">.</span><span class="mi">92</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">,</span><span class="o">.</span><span class="mo">04</span><span class="p">),</span>
            <span class="s">&#39;SouthOutside&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;horizontal&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">2</span><span class="p">,</span><span class="o">.</span><span class="mo">06</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">,</span><span class="o">.</span><span class="mo">04</span><span class="p">),</span>
            <span class="s">&#39;EastOutside&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;vertical&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">9</span><span class="p">,</span><span class="o">.</span><span class="mi">21</span><span class="p">,</span><span class="o">.</span><span class="mo">03</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">),</span>
            <span class="s">&#39;WestOutside&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;vertical&#39;</span><span class="p">,</span><span class="o">.</span><span class="mo">01</span><span class="p">,</span><span class="o">.</span><span class="mi">21</span><span class="p">,</span><span class="o">.</span><span class="mo">03</span><span class="p">,</span><span class="o">.</span><span class="mi">6</span><span class="p">)</span>
            <span class="p">}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_doing_PS</span> <span class="o">=</span> <span class="bp">False</span>  <span class="c"># indicator for PostScript hardcopy</span>

        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting backend standard variables&quot;</span>
            <span class="k">for</span> <span class="n">disp</span> <span class="ow">in</span> <span class="s">&#39;self._markers self._colors self._line_styles&#39;</span><span class="o">.</span><span class="n">split</span><span class="p">():</span>
                <span class="k">print</span> <span class="n">disp</span><span class="p">,</span> <span class="nb">eval</span><span class="p">(</span><span class="n">disp</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_scale</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set linear or logarithmic (base 10) axis scale.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting scales&quot;</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;scale&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;loglog&#39;</span><span class="p">:</span>
            <span class="c"># use logarithmic scale on both x- and y-axis</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set logscale xy&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set autoscale&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;logx&#39;</span><span class="p">:</span>
            <span class="c"># use logarithmic scale on x-axis and linear scale on y-axis</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set logscale x&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset logscale y&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set autoscale&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;logy&#39;</span><span class="p">:</span>
            <span class="c"># use linear scale on x-axis and logarithmic scale on y-axis</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset logscale x&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set logscale y&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set autoscale&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;linear&#39;</span><span class="p">:</span>
            <span class="c"># use linear scale on both x- and y-axis</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset logscale x&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset logscale y&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set autoscale&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add text labels for x-, y-, and z-axis.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting labels&quot;</span>
        <span class="n">xlabel</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xlabel&#39;</span><span class="p">)</span>
        <span class="n">ylabel</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ylabel&#39;</span><span class="p">)</span>
        <span class="n">zlabel</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zlabel&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">xlabel</span><span class="p">:</span>
            <span class="c"># add a text label on x-axis</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set xlabel &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">xlabel</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset xlabel&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ylabel</span><span class="p">:</span>
            <span class="c"># add a text label on y-axis</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set ylabel &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">ylabel</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset ylabel&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">zlabel</span><span class="p">:</span>
            <span class="c"># add a text label on z-axis</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set zlabel &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">zlabel</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset zlabel&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_title</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a title at the top of the axis.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting title&quot;</span>
        <span class="n">title</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;title&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">title</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set title &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">title</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset title&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_limits</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set axis limits in x, y, and z direction.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting axis limits&quot;</span>
        <span class="n">mode</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;mode&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;auto&#39;</span><span class="p">:</span>
            <span class="c"># let plotting package set &#39;nice&#39; axis limits in the x, y,</span>
            <span class="c"># and z direction. If this is not automated in the plotting</span>
            <span class="c"># package, one can use the following limits:</span>
            <span class="c">#xmin, xmax, ymin, ymax, zmin, zmax = ax.get_limits()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set xrange[*:*]&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set yrange[*:*]&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set zrange[*:*]&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;manual&#39;</span><span class="p">:</span>
            <span class="c"># (some) axis limits are frozen</span>
            <span class="n">xmin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmin&#39;</span><span class="p">)</span>
            <span class="n">xmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmax&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">xmin</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">xmax</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># set x-axis limits</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set xrange[</span><span class="si">%g</span><span class="s">:</span><span class="si">%g</span><span class="s">]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># let plotting package set x-axis limits or use</span>
                <span class="c">#xmin, xmax = ax.getp(&#39;xlim&#39;)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set xrange[*:*]&#39;</span><span class="p">)</span>

            <span class="n">ymin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ymin&#39;</span><span class="p">)</span>
            <span class="n">ymax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ymax&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">ymin</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">ymax</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># set y-axis limits</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set yrange[</span><span class="si">%g</span><span class="s">:</span><span class="si">%g</span><span class="s">]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># let plotting package set y-axis limits or use</span>
                <span class="c">#ymin, ymax = ax.getp(&#39;ylim&#39;)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set yrange[*:*]&#39;</span><span class="p">)</span>

            <span class="n">zmin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zmin&#39;</span><span class="p">)</span>
            <span class="n">zmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zmax&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">zmin</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">zmax</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># set z-axis limits</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set zrange[</span><span class="si">%g</span><span class="s">:</span><span class="si">%g</span><span class="s">]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># let plotting package set z-axis limits or use</span>
                <span class="c">#zmin, zmax = ax.getp(&#39;zlim&#39;)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set zrange[*:*]&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;tight&#39;</span><span class="p">:</span>
            <span class="c"># set the limits on the axis to the range of the data. If</span>
            <span class="c"># this is not automated in the plotting package, one can</span>
            <span class="c"># use the following limits:</span>
            <span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_limits</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set xrange[</span><span class="si">%g</span><span class="s">:</span><span class="si">%g</span><span class="s">]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set yrange[</span><span class="si">%g</span><span class="s">:</span><span class="si">%g</span><span class="s">]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set zrange[</span><span class="si">%g</span><span class="s">:</span><span class="si">%g</span><span class="s">]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span><span class="p">))</span>
        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;fill&#39;</span><span class="p">:</span>
            <span class="c"># not sure about this</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_position</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set axes position.&quot;&quot;&quot;</span>
        <span class="n">rect</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;viewport&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">rect</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span><span class="nb">tuple</span><span class="p">))</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">rect</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span> <span class="ow">and</span> \
               <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;pth&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># axes position is defined. In Matlab rect is defined as</span>
            <span class="c"># [left,bottom,width,height], where the four parameters are</span>
            <span class="c"># location values between 0 and 1 ((0,0) is the lower-left</span>
            <span class="c"># corner and (1,1) is the upper-right corner).</span>
            <span class="c"># NOTE: This can be different in the plotting package.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set origin </span><span class="si">%g</span><span class="s">,</span><span class="si">%g</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">rect</span><span class="p">[:</span><span class="mi">2</span><span class="p">]))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size </span><span class="si">%g</span><span class="s">,</span><span class="si">%g</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">rect</span><span class="p">[</span><span class="mi">2</span><span class="p">:]))</span>

    <span class="k">def</span> <span class="nf">_set_daspect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set data aspect ratio.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspectmode&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;manual&#39;</span><span class="p">:</span>
            <span class="n">dar</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>  <span class="c"># dar is a list (len(dar) is 3).</span>
            <span class="c"># In Gnuplot we cannot set individual aspects for the different</span>
            <span class="c"># axes. Therefore we use dar[0] as the aspect ratio:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size ratio </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">dar</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">elif</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspectmode&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;equal&#39;</span><span class="p">:</span>
            <span class="n">xmin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmin&#39;</span><span class="p">)</span>
            <span class="n">xmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmax&#39;</span><span class="p">)</span>
            <span class="n">ymin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ymin&#39;</span><span class="p">)</span>
            <span class="n">ymax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ymax&#39;</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">r</span> <span class="o">=</span> <span class="p">(</span><span class="n">ymax</span><span class="o">-</span><span class="n">ymin</span><span class="p">)</span><span class="o">/</span><span class="nb">float</span><span class="p">(</span><span class="n">xmax</span><span class="o">-</span><span class="n">xmin</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;daspectmode=&quot;equal&quot; requires the axes to be explicitly set&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size ratio </span><span class="si">%g</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">r</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># daspectmode is &#39;auto&#39;. Plotting package handles data</span>
            <span class="c"># aspect ratio automatically.</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_axis_method</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="n">method</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;method&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;equal&#39;</span><span class="p">:</span>
            <span class="c"># tick mark increments on the x-, y-, and z-axis should</span>
            <span class="c"># be equal in size.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size ratio -1&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;image&#39;</span><span class="p">:</span>
            <span class="c"># same effect as axis(&#39;equal&#39;) and axis(&#39;tight&#39;)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size ratio -1&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;square&#39;</span><span class="p">:</span>
            <span class="c"># make the axis box square in size</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size square&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;normal&#39;</span><span class="p">:</span>
            <span class="c"># full size axis box</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size noratio&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size nosquare&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;vis3d&#39;</span><span class="p">:</span>
            <span class="c"># freeze data aspect ratio when rotating 3D objects</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_coordinate_system</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Use either the default Cartesian coordinate system or a</span>
<span class="sd">        matrix coordinate system.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">direction</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;direction&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">direction</span> <span class="o">==</span> <span class="s">&#39;ij&#39;</span><span class="p">:</span>
            <span class="c"># Use matrix coordinates. The origin of the coordinate</span>
            <span class="c"># system is the upper-left corner. The i-axis should be</span>
            <span class="c"># vertical and numbered from top to bottom, while the j-axis</span>
            <span class="c"># should be horizontal and numbered from left to right.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set yrange [] reverse&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">direction</span> <span class="o">==</span> <span class="s">&#39;xy&#39;</span><span class="p">:</span>
            <span class="c"># use the default Cartesian axes form. The origin is at the</span>
            <span class="c"># lower-left corner. The x-axis is vertical and numbered</span>
            <span class="c"># from left to right, while the y-axis is vertical and</span>
            <span class="c"># numbered from bottom to top.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set yrange [] noreverse&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_box</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Turn box around axes boundary on or off.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting box&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;box&#39;</span><span class="p">):</span>
            <span class="c"># display box</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set border 4095 linetype -1 linewidth .4&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># do not display box</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_grid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Turn grid lines on or off.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting grid&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;grid&#39;</span><span class="p">):</span>
            <span class="c"># turn grid lines on</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set grid&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn grid lines off</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset grid&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_hidden_line_removal</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Turn on/off hidden line removal for meshes.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting hidden line removal&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;hidden&#39;</span><span class="p">):</span>
            <span class="c"># turn hidden line removal on</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set hidden3d&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn hidden line removal off</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset hidden3d&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_colorbar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a colorbar to the axis.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting colorbar&quot;</span>
        <span class="n">cbar</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;colorbar&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">cbar</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;visible&#39;</span><span class="p">):</span>
            <span class="c"># turn on colorbar</span>
            <span class="n">cbar_title</span> <span class="o">=</span> <span class="n">cbar</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cbtitle&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set cblabel &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">cbar_title</span><span class="p">)</span>
            <span class="n">cbar_location</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colorbar_locations</span><span class="p">[</span><span class="n">cbar</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cblocation&#39;</span><span class="p">)]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set style line 2604 linetype -1 linewidth .4&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set colorbox </span><span class="si">%s</span><span class="s"> user border 2604 origin </span><span class="si">%g</span><span class="s">,</span><span class="si">%g</span><span class="s"> size </span><span class="si">%g</span><span class="s">,</span><span class="si">%g</span><span class="s">&#39;</span>\
                    <span class="o">%</span> <span class="n">cbar_location</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn off colorbar</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset colorbox&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_caxis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the color axis scale.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting caxis&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;caxismode&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;manual&#39;</span><span class="p">:</span>
            <span class="n">cmin</span><span class="p">,</span> <span class="n">cmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;caxis&#39;</span><span class="p">)</span>
            <span class="c"># NOTE: cmin and cmax might be None:</span>
            <span class="k">if</span> <span class="n">cmin</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">cmax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">cmin</span><span class="p">,</span> <span class="n">cmax</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span>
            <span class="c"># set color axis scaling according to cmin and cmax</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set cbrange [</span><span class="si">%s</span><span class="s">:</span><span class="si">%s</span><span class="s">]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cmin</span><span class="p">,</span><span class="n">cmax</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># use autoranging for color axis scale</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set cbrange [*:*]&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_colormap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the colormap.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting colormap&quot;</span>
        <span class="n">cmap</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;colormap&#39;</span><span class="p">)</span>
        <span class="c"># cmap is plotting package dependent</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cmap</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">and</span> <span class="n">cmap</span> <span class="o">!=</span> <span class="s">&#39;default&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cmap</span><span class="p">,</span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span><span class="nb">list</span><span class="p">))</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> \
                 <span class="nb">isinstance</span><span class="p">(</span><span class="n">cmap</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> \
                 <span class="nb">isinstance</span><span class="p">(</span><span class="n">cmap</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">and</span> \
                 <span class="nb">isinstance</span><span class="p">(</span><span class="n">cmap</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="nb">int</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set palette rgbformulae </span><span class="si">%d</span><span class="s">,</span><span class="si">%d</span><span class="s">,</span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">cmap</span><span class="p">)</span> <span class="c"># model RGB?</span>
        <span class="k">elif</span> <span class="n">operator</span><span class="o">.</span><span class="n">isSequenceType</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">m</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="n">shape</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span>
            <span class="k">assert</span> <span class="n">n</span><span class="o">==</span><span class="mi">3</span><span class="p">,</span> <span class="s">&quot;colormap must be </span><span class="si">%d</span><span class="s">x3, not </span><span class="si">%d</span><span class="s">x</span><span class="si">%d</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">)</span>
            <span class="n">tmpf</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">suffix</span><span class="o">=</span><span class="s">&#39;.map&#39;</span><span class="p">)</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span> <span class="p">(</span><span class="n">tmpf</span><span class="p">,</span> <span class="s">&quot;w&quot;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">):</span>
                <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%g</span><span class="s"> </span><span class="si">%g</span><span class="s"> </span><span class="si">%g</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cmap</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span><span class="n">cmap</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span><span class="n">cmap</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="mi">2</span><span class="p">]))</span>
            <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set palette file &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">tmpf</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span> <span class="c"># use default colormap</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set palette model RGB defined (0 &quot;blue&quot;, 3 &quot;cyan&quot;, &#39;</span> \
                    <span class="s">&#39;4 &quot;green&quot;, 5 &quot;yellow&quot;, 8 &quot;red&quot;, 10 &quot;black&quot;)&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set viewpoint specification.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting view&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset view&#39;</span><span class="p">)</span>
        <span class="n">cam</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camera&#39;</span><span class="p">)</span>
        <span class="n">view</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;view&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">view</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c"># setup a default 2D view</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set view map&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">view</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
            <span class="n">az</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;azimuth&#39;</span><span class="p">)</span>
            <span class="n">el</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;elevation&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">az</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">el</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># azimuth or elevation is not given. Set up a default</span>
                <span class="c"># 3D view (az=-37.5 and el=30 is the default 3D view in</span>
                <span class="c"># Matlab).</span>
                <span class="n">az</span><span class="p">,</span> <span class="n">el</span> <span class="o">=</span> <span class="p">(</span><span class="mi">60</span><span class="p">,</span><span class="mi">325</span><span class="p">)</span> <span class="c"># default 3D view in Gnuplot</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">az</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">az</span> <span class="o">&lt;=</span> <span class="mi">180</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">el</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">el</span> <span class="o">&lt;=</span> <span class="mi">360</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set view </span><span class="si">%d</span><span class="s">,</span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">az</span><span class="p">,</span><span class="n">el</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&#39;view (</span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">) out of range [0:180,0:360]&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">az</span><span class="p">,</span><span class="n">el</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cammode&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;manual&#39;</span><span class="p">:</span>
                <span class="c"># for advanced camera handling:</span>
                <span class="n">roll</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camroll&#39;</span><span class="p">)</span>
                <span class="n">zoom</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camzoom&#39;</span><span class="p">)</span>
                <span class="n">dolly</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camdolly&#39;</span><span class="p">)</span>
                <span class="n">target</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camtarget&#39;</span><span class="p">)</span>
                <span class="n">position</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;campos&#39;</span><span class="p">)</span>
                <span class="n">up_vector</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camup&#39;</span><span class="p">)</span>
                <span class="n">view_angle</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camva&#39;</span><span class="p">)</span>
                <span class="n">projection</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camproj&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_axis_props</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting axis properties&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_title</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_scale</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_limits</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_position</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_axis_method</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_daspect</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_coordinate_system</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_hidden_line_removal</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_colorbar</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_caxis</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_colormap</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_view</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;visible&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set xtics&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set ytics&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set ztics&#39;</span><span class="p">)</span>
            <span class="c"># set up some nice default graph borders:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set border 1+2+4+8+16 linetype -1 linewidth .4&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_labels</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_box</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_grid</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn off all axis labeling, tickmarks, and background</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset border&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset grid&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset xtics&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset ytics&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset ztics&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_fix_latex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">legend</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Translate latex syntax in title and legend to enhanced</span>
<span class="sd">        PostScript symbols (enable greek letters, super- and subscripts,</span>
<span class="sd">        etc.).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
        <span class="c"># General fix of latex syntax (more readable)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;**&#39;</span><span class="p">,</span> <span class="s">&#39;^&#39;</span><span class="p">)</span>
        <span class="c">#legend = legend.replace(&#39;*&#39;, &#39;&#39;)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;$&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;{&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;}&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="c"># Translate greek letters if PostScript output</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_doing_PS</span><span class="p">:</span>
            <span class="n">ps2greek</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
                <span class="n">A</span><span class="o">=</span><span class="s">&#39;Alpha&#39;</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="s">&#39;Nu&#39;</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="s">&#39;alpha&#39;</span><span class="p">,</span>	<span class="n">n</span><span class="o">=</span><span class="s">&#39;nu&#39;</span><span class="p">,</span> <span class="n">B</span><span class="o">=</span><span class="s">&#39;Beta&#39;</span><span class="p">,</span> <span class="n">O</span><span class="o">=</span><span class="s">&#39;Omicron&#39;</span><span class="p">,</span>
                <span class="n">b</span><span class="o">=</span><span class="s">&#39;beta&#39;</span><span class="p">,</span> <span class="n">o</span><span class="o">=</span><span class="s">&#39;omicron&#39;</span><span class="p">,</span> <span class="n">C</span><span class="o">=</span><span class="s">&#39;Chi&#39;</span><span class="p">,</span> <span class="n">P</span><span class="o">=</span><span class="s">&#39;Pi&#39;</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s">&#39;chi&#39;</span><span class="p">,</span>	<span class="n">p</span><span class="o">=</span><span class="s">&#39;pi&#39;</span><span class="p">,</span>
                <span class="n">D</span><span class="o">=</span><span class="s">&#39;Delta&#39;</span><span class="p">,</span> <span class="n">Q</span><span class="o">=</span><span class="s">&#39;Theta&#39;</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="s">&#39;delta&#39;</span><span class="p">,</span> <span class="n">q</span><span class="o">=</span><span class="s">&#39;theta&#39;</span><span class="p">,</span> <span class="n">E</span><span class="o">=</span><span class="s">&#39;Epsilon&#39;</span><span class="p">,</span>
                <span class="n">R</span><span class="o">=</span><span class="s">&#39;Rho&#39;</span><span class="p">,</span> <span class="n">e</span><span class="o">=</span><span class="s">&#39;epsilon&#39;</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="s">&#39;rho&#39;</span><span class="p">,</span> <span class="n">F</span><span class="o">=</span><span class="s">&#39;Phi&#39;</span><span class="p">,</span> <span class="n">S</span><span class="o">=</span><span class="s">&#39;Sigma&#39;</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="s">&#39;phi&#39;</span><span class="p">,</span>
                <span class="n">s</span><span class="o">=</span><span class="s">&#39;sigma&#39;</span><span class="p">,</span> <span class="n">G</span><span class="o">=</span><span class="s">&#39;Gamma&#39;</span><span class="p">,</span> <span class="n">T</span><span class="o">=</span><span class="s">&#39;Tau&#39;</span><span class="p">,</span> <span class="n">g</span><span class="o">=</span><span class="s">&#39;gamma&#39;</span><span class="p">,</span> <span class="n">t</span><span class="o">=</span><span class="s">&#39;tau&#39;</span><span class="p">,</span>
                <span class="n">H</span><span class="o">=</span><span class="s">&#39;Eta&#39;</span><span class="p">,</span> <span class="n">U</span><span class="o">=</span><span class="s">&#39;Upsilon&#39;</span><span class="p">,</span> <span class="n">h</span><span class="o">=</span><span class="s">&#39;eta&#39;</span><span class="p">,</span> <span class="n">u</span><span class="o">=</span><span class="s">&#39;upsilon&#39;</span><span class="p">,</span>
                <span class="n">I</span><span class="o">=</span><span class="s">&#39;iota&#39;</span><span class="p">,</span> <span class="n">W</span><span class="o">=</span><span class="s">&#39;Omega&#39;</span><span class="p">,</span> <span class="n">i</span><span class="o">=</span><span class="s">&#39;iota&#39;</span><span class="p">,</span> <span class="n">w</span><span class="o">=</span><span class="s">&#39;omega&#39;</span><span class="p">,</span>
                <span class="n">K</span><span class="o">=</span><span class="s">&#39;Kappa&#39;</span><span class="p">,</span> <span class="n">X</span><span class="o">=</span><span class="s">&#39;Xi&#39;</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="s">&#39;kappa&#39;</span><span class="p">,</span> <span class="n">l</span><span class="o">=</span><span class="s">&#39;lambda&#39;</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="s">&#39;xi&#39;</span><span class="p">,</span>
                <span class="n">L</span><span class="o">=</span><span class="s">&#39;Lambda&#39;</span><span class="p">,</span> <span class="n">Y</span><span class="o">=</span><span class="s">&#39;Psi&#39;</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="s">&#39;psi&#39;</span><span class="p">,</span>
                <span class="n">M</span><span class="o">=</span><span class="s">&#39;Mu&#39;</span><span class="p">,</span> <span class="n">Z</span><span class="o">=</span><span class="s">&#39;Zeta&#39;</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="s">&#39;mu&#39;</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="s">&#39;zeta&#39;</span><span class="p">)</span>
            <span class="n">greek2ps</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">ps2greek</span><span class="p">:</span>
                <span class="n">greek2ps</span><span class="p">[</span><span class="n">ps2greek</span><span class="p">[</span><span class="n">char</span><span class="p">]]</span> <span class="o">=</span> <span class="n">char</span>

            <span class="k">for</span> <span class="n">greek_letter</span> <span class="ow">in</span> <span class="n">greek2ps</span><span class="p">:</span>
                <span class="n">glb</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\\</span><span class="s">&#39;</span> <span class="o">+</span> <span class="n">greek_letter</span>
                <span class="k">if</span> <span class="n">glb</span> <span class="ow">in</span> <span class="n">legend</span><span class="p">:</span>
                    <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">glb</span><span class="p">,</span> <span class="s">&#39;{/Symbol </span><span class="si">%s</span><span class="s">}&#39;</span> <span class="o">%</span>
                                            <span class="n">greek2ps</span><span class="p">[</span><span class="n">greek_letter</span><span class="p">])</span>
            <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;*&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>

        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\\</span><span class="s">&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">legend</span>

    <span class="k">def</span> <span class="nf">_get_linespecs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the line marker, line color, line style, and</span>
<span class="sd">        line width of the item.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">marker</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_markers</span><span class="p">[</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linemarker&#39;</span><span class="p">)]</span>
        <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="p">[</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linecolor&#39;</span><span class="p">)]</span>
        <span class="n">style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_styles</span><span class="p">[</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linetype&#39;</span><span class="p">)]</span>
        <span class="n">width</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linewidth&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span>

    <span class="k">def</span> <span class="nf">_get_withstring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">width</span><span class="p">:</span>
            <span class="n">width</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">width</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>

        <span class="n">withstring</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="k">if</span> <span class="n">color</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">style</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">marker</span><span class="p">:</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;points lt </span><span class="si">%d</span><span class="s"> pt </span><span class="si">%d</span><span class="s"> ps </span><span class="si">%d</span><span class="s"> &quot;</span> \
                                 <span class="o">%</span> <span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="n">marker</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;lines lt </span><span class="si">%d</span><span class="s"> lw </span><span class="si">%d</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">style</span> <span class="o">==</span> <span class="s">&#39;lines&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">marker</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>  <span class="c"># marker is not set</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;lines lt </span><span class="si">%d</span><span class="s"> lw </span><span class="si">%d</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;linespoints lt </span><span class="si">%d</span><span class="s"> lw </span><span class="si">%d</span><span class="s"> pt </span><span class="si">%d</span><span class="s">&quot;</span> <span class="o">%</span> \
                                 <span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">marker</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>  <span class="c"># no color</span>
            <span class="k">if</span> <span class="n">style</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">marker</span><span class="p">:</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;points pt </span><span class="si">%d</span><span class="s"> ps </span><span class="si">%d</span><span class="s"> &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">marker</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;lines&quot;</span>  <span class="c"># no color, no style, no marker</span>
            <span class="k">elif</span> <span class="n">style</span> <span class="o">==</span> <span class="s">&#39;lines&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">marker</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>  <span class="c"># marker is not set</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;lines&quot;</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">withstring</span> <span class="o">=</span> <span class="s">&quot;linespoints pt </span><span class="si">%d</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">marker</span>
        <span class="k">return</span> <span class="n">withstring</span>

    <span class="k">def</span> <span class="nf">_add_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a 2D or 3D curve to the scene.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a line&quot;</span>
        <span class="c"># get data:</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">))</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">))</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="c"># get line specifiactions:</span>
        <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_linespecs</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="n">withstring</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_withstring</span><span class="p">(</span><span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">z</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># zdata is given, add a 3D curve:</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)),</span>
                      <span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="n">withstring</span><span class="p">,</span>
                      <span class="s">&#39;using&#39;</span><span class="p">:</span> <span class="s">&#39;1:2:($3)&#39;</span><span class="p">}</span>
            <span class="n">data</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">arrayconverter</span><span class="p">(</span><span class="n">x</span><span class="p">),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">y</span><span class="p">),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">squeeze</span><span class="p">(</span><span class="n">z</span><span class="p">)),</span>
                                <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set parametric&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># no zdata, add a 2D curve:</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)),</span>
                      <span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="n">withstring</span><span class="p">,</span>
                      <span class="s">&#39;using&#39;</span><span class="p">:</span> <span class="s">&#39;1:($2)&#39;</span><span class="p">}</span>

            <span class="n">data</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">arrayconverter</span><span class="p">(</span><span class="n">x</span><span class="p">),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">y</span><span class="p">),</span>
                                <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span>


    <span class="k">def</span> <span class="nf">_add_filled_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a 2D or 3D filled curve.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a line&quot;</span>
        <span class="c"># get data:</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">))</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">))</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="c"># get line specifiactions:</span>
        <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_linespecs</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="n">facecolor</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;facecolor&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">facecolor</span><span class="p">:</span>
            <span class="n">facecolor</span> <span class="o">=</span> <span class="n">color</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">facecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">facecolor</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
        <span class="n">edgecolor</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;edgecolor&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">edgecolor</span><span class="p">:</span>
            <span class="n">edgecolor</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>  <span class="c"># use black for now</span>
            <span class="c"># FIXME: Should use ax.getp(&#39;fgcolor&#39;) as default edgecolor</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">edgecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">edgecolor</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>

        <span class="n">withstring</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_withstring</span><span class="p">(</span><span class="n">marker</span><span class="p">,</span> <span class="n">edgecolor</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">z</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># zdata is given, add a 3D curve:</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)),</span>
                      <span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="s">&#39;filledcurve&#39;</span><span class="p">,</span>
                      <span class="s">&#39;using&#39;</span><span class="p">:</span> <span class="s">&#39;1:2:($3)&#39;</span><span class="p">}</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set parametric&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># no zdata, add a 2D curve:</span>
            <span class="n">kwargs1</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)),</span>
                       <span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="s">&#39;filledcurve </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">facecolor</span><span class="p">,</span>
                       <span class="s">&#39;using&#39;</span><span class="p">:</span> <span class="s">&#39;1:($2)&#39;</span><span class="p">}</span>
            <span class="n">kwargs2</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="n">withstring</span><span class="p">,</span> <span class="s">&#39;using&#39;</span><span class="p">:</span> <span class="s">&#39;1:($2)&#39;</span><span class="p">}</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs1</span><span class="p">),</span>
                    <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs2</span><span class="p">),</span>
                    <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">([</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]],</span> <span class="p">[</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">y</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]],</span> <span class="o">**</span><span class="n">kwargs2</span><span class="p">)]</span>
        <span class="k">return</span> <span class="n">data</span>

    <span class="k">def</span> <span class="nf">_add_bar_graph</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">shading</span><span class="o">=</span><span class="s">&#39;faceted&#39;</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a bar graph&quot;</span>
        <span class="c"># get data:</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">)</span>
        <span class="c"># get line specifiactions:</span>
        <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_linespecs</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">y</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span><span class="n">y</span><span class="p">,(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">),</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">nx</span><span class="p">,</span> <span class="n">ny</span> <span class="o">=</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>

        <span class="n">barticks</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;barticks&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">barticks</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">barticks</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">nx</span><span class="p">)</span>
        <span class="n">xtics</span> <span class="o">=</span> <span class="s">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;&quot;</span><span class="si">%s</span><span class="s">&quot; </span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">i</span><span class="p">)</span> \
                           <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">m</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">barticks</span><span class="p">)])</span>
        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;rotated_barticks&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&quot;set xtics rotate (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="n">xtics</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&quot;set xtics (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="n">xtics</span><span class="p">)</span>

        <span class="n">barwidth</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;barwidth&#39;</span><span class="p">)</span><span class="o">/</span><span class="mi">10</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set boxwidth </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">barwidth</span><span class="p">)</span>
        <span class="n">edgecolor</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;edgecolor&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">edgecolor</span><span class="p">:</span>
            <span class="n">edgecolor</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>  <span class="c"># use black for now</span>
            <span class="c"># FIXME: edgecolor should be same as ax.getp(&#39;fgcolor&#39;) by default</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">edgecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">edgecolor</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">shading</span> <span class="o">==</span> <span class="s">&#39;faceted&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set style fill solid 1.00 border </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">edgecolor</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set style fill solid 1.00&#39;</span><span class="p">)</span>

        <span class="n">facecolor</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;facecolor&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">facecolor</span><span class="p">:</span>
            <span class="n">facecolor</span> <span class="o">=</span> <span class="n">color</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">facecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">facecolor</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>  <span class="c"># use blue as default</span>

        <span class="n">step</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;barstepsize&#39;</span><span class="p">)</span><span class="o">/</span><span class="mi">10</span>

        <span class="n">center</span> <span class="o">=</span> <span class="n">floor</span><span class="p">(</span><span class="n">ny</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">start</span> <span class="o">=</span> <span class="o">-</span><span class="n">step</span><span class="o">*</span><span class="n">center</span>
        <span class="n">stop</span> <span class="o">=</span> <span class="n">step</span><span class="o">*</span><span class="n">center</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">ny</span><span class="o">%</span><span class="mi">2</span><span class="p">:</span>
            <span class="n">start</span> <span class="o">+=</span> <span class="n">step</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">stop</span> <span class="o">-=</span> <span class="n">step</span><span class="o">/</span><span class="mi">2</span>
        <span class="n">a</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="n">start</span><span class="p">,</span><span class="n">stop</span><span class="p">,</span><span class="n">ny</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ny</span><span class="p">):</span>
            <span class="n">y_</span> <span class="o">=</span> <span class="n">y</span><span class="p">[:,</span><span class="n">j</span><span class="p">]</span>
            <span class="n">x_</span> <span class="o">=</span> <span class="n">array</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">nx</span><span class="p">))</span> <span class="o">+</span> <span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linecolor&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;facecolor&#39;</span><span class="p">):</span>
                <span class="n">c</span> <span class="o">=</span> <span class="n">j</span><span class="o">+</span><span class="mi">1</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">c</span> <span class="o">=</span> <span class="n">facecolor</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="s">&#39;boxes linecolor </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">c</span><span class="p">}</span>
            <span class="n">legend</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">legend</span><span class="p">:</span>
                <span class="n">legend</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)))[</span><span class="n">j</span><span class="p">]</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;title&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">legend</span>
            <span class="c">#print &quot;|%s|&quot; % self._fix_latex(item.getp(&#39;legend&#39;))</span>
            <span class="c"># does not work:</span>
            <span class="c">#kwargs = {&#39;with&#39;: &#39;boxes %s&#39; % c,</span>
            <span class="c">#          &#39;title&#39;: self._fix_latex(item.getp(&#39;legend&#39;)),}</span>
            <span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">x_</span><span class="p">,</span> <span class="n">y_</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">data</span>

    <span class="k">def</span> <span class="nf">_add_surface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">shading</span><span class="o">=</span><span class="s">&#39;faceted&#39;</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a surface&quot;</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">)</span>  <span class="c"># grid component in x-direction</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">)</span>  <span class="c"># grid component in y-direction</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>  <span class="c"># scalar field</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cdata&#39;</span><span class="p">)</span>  <span class="c"># pseudocolor data (can be None)</span>
        <span class="c"># get line specifiactions:</span>
        <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_linespecs</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">width</span><span class="p">:</span>
            <span class="n">width</span> <span class="o">=</span> <span class="mf">1.0</span>
        <span class="n">width</span> <span class="o">=</span> <span class="n">width</span> <span class="o">-</span> <span class="n">width</span><span class="o">/</span><span class="mi">2</span>
        <span class="n">edgecolor</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;edgecolor&#39;</span><span class="p">)</span>
        <span class="c">#facecolor = item.getp(&#39;facecolor&#39;)</span>
        <span class="c">#if facecolor and facecolor in self._colors:</span>
        <span class="c">#    facecolor = self._colors[facecolor]</span>

        <span class="n">withstring</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set surface&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;wireframe&#39;</span><span class="p">):</span>
            <span class="c"># wireframe mesh (as produced by mesh or meshc)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset pm3d&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">edgecolor</span> <span class="o">==</span> <span class="s">&#39;&#39;</span><span class="p">:</span>
                <span class="n">withstring</span> <span class="o">=</span> <span class="s">&#39;l palette&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">edgecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">edgecolor</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
                <span class="n">withstring</span> <span class="o">+=</span> <span class="s">&#39;lines lt </span><span class="si">%s</span><span class="s"> lw </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">edgecolor</span><span class="p">,</span><span class="n">width</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># colored surface (as produced by surf, surfc, or pcolor)</span>
            <span class="c"># use keyword argument shading to set the color shading mode</span>
            <span class="k">if</span> <span class="n">shading</span> <span class="o">==</span> <span class="s">&#39;flat&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set pm3d at s solid&#39;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">shading</span> <span class="o">==</span> <span class="s">&#39;faceted&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set pm3d at s solid hidden3d 100&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">edgecolor</span> <span class="o">==</span> <span class="s">&#39;&#39;</span><span class="p">:</span>
                    <span class="n">edgecolor</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>  <span class="c"># use black for now</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">edgecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">edgecolor</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set style line 100 lt </span><span class="si">%s</span><span class="s"> lw </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">edgecolor</span><span class="p">,</span><span class="n">width</span><span class="p">))</span>
            <span class="k">elif</span> <span class="n">shading</span> <span class="o">==</span> <span class="s">&#39;interp&#39;</span><span class="p">:</span>
                <span class="c"># Interpolated shading requires Gnuplot &gt;= 4.2</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set pm3d implicit at s&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set pm3d scansautomatic&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set pm3d interpolate 10,10&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set pm3d flush begin ftriangles nohidden3d&#39;</span><span class="p">)</span>
            <span class="n">withstring</span> <span class="o">+=</span> <span class="s">&#39;l palette&#39;</span>

        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;xy&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">,:];</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">z</span> <span class="o">=</span> <span class="n">transpose</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">[:,</span><span class="mi">0</span><span class="p">];</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">,:]</span>
        <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)),</span>
                  <span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="n">withstring</span><span class="p">,</span>
                  <span class="s">&#39;binary&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">}</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">GridData</span><span class="p">(</span><span class="n">arrayconverter</span><span class="p">(</span><span class="n">z</span><span class="p">),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">x</span><span class="p">),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">y</span><span class="p">),</span>
                                <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span>

    <span class="k">def</span> <span class="nf">_add_contours</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">placement</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="c"># The placement keyword can be either None or &#39;bottom&#39;. The</span>
        <span class="c"># latter specifies that the contours should be placed at the</span>
        <span class="c"># bottom (as in meshc or surfc).</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding contours&quot;</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">)</span>  <span class="c"># grid component in x-direction</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">)</span>  <span class="c"># grid component in y-direction</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>  <span class="c"># scalar field</span>

        <span class="n">filled</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;filled&#39;</span><span class="p">)</span>  <span class="c"># draw filled contour plot if True</span>

        <span class="n">cvector</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cvector&#39;</span><span class="p">)</span>
        <span class="n">clevels</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clevels&#39;</span><span class="p">)</span>  <span class="c"># number of contour levels</span>
        <span class="k">if</span> <span class="n">cvector</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># the contour levels are chosen automatically</span>
            <span class="c">#cvector =</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set cntrparam levels auto </span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">clevels</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">cvector</span> <span class="o">=</span> <span class="s">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">cvector</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set cntrparam levels discrete </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">cvector</span><span class="p">)</span>

        <span class="n">location</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clocation&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">location</span> <span class="o">==</span> <span class="s">&#39;surface&#39;</span><span class="p">:</span>
            <span class="c"># place the contours at the corresponding z level (contour3)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set contour surface&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset surface&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset pm3d&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">location</span> <span class="o">==</span> <span class="s">&#39;base&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">placement</span> <span class="o">==</span> <span class="s">&#39;bottom&#39;</span><span class="p">:</span>
                <span class="c"># place the contours at the bottom (as in meshc or surfc)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set contour base&#39;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">filled</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set contour base&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set style fill solid&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set pm3d at s solid&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set palette maxcolors </span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clevels&#39;</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># standard contour plot</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set contour base&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset surface&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset pm3d&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clabels&#39;</span><span class="p">):</span>
            <span class="c"># add labels on the contour curves</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set clabel&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset clabel&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;xy&#39;</span><span class="p">:</span>
            <span class="n">z</span> <span class="o">=</span> <span class="n">transpose</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">,:];</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">[:,</span><span class="mi">0</span><span class="p">];</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">,:]</span>
        <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)),</span>
                  <span class="s">&#39;binary&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                  <span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="s">&#39;l palette&#39;</span><span class="p">}</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">GridData</span><span class="p">(</span><span class="n">arrayconverter</span><span class="p">(</span><span class="n">z</span><span class="p">),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">x</span><span class="p">),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">y</span><span class="p">),</span>
                                <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span>

    <span class="k">def</span> <span class="nf">_add_vectors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding vectors&quot;</span>
        <span class="c"># uncomment the following command if there is no support for</span>
        <span class="c"># automatic scaling of vectors in the current plotting package:</span>
        <span class="n">item</span><span class="o">.</span><span class="n">scale_vectors</span><span class="p">()</span>

        <span class="c"># grid components:</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="c"># vector components:</span>
        <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;udata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;wdata&#39;</span><span class="p">)</span>
        <span class="c"># get line specifiactions (marker=&#39;.&#39; means no marker):</span>
        <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_linespecs</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="n">withstring</span> <span class="o">=</span> <span class="s">&#39;vectors&#39;</span>
        <span class="k">if</span> <span class="n">color</span><span class="p">:</span>
            <span class="n">withstring</span> <span class="o">+=</span> <span class="s">&#39; lt </span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">color</span>
        <span class="k">if</span> <span class="n">width</span><span class="p">:</span>
            <span class="n">withstring</span> <span class="o">+=</span> <span class="s">&#39; lw </span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>

        <span class="c"># scale the vectors according to this variable (scale=0 should</span>
        <span class="c"># turn off automatic scaling):</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;arrowscale&#39;</span><span class="p">)</span>

        <span class="n">filled</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;filledarrows&#39;</span><span class="p">)</span> <span class="c"># draw filled arrows if True</span>

        <span class="k">if</span> <span class="n">z</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">w</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># draw velocity vectors as arrows with components (u,v,w) at</span>
            <span class="c"># points (x,y,z):</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">None</span>  <span class="c"># no support for vectors in 3D space in Gnuplot</span>
            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;3D vector fields not implemented in </span><span class="si">%s</span><span class="s"> backend&quot;</span> <span class="o">%</span> <span class="n">backend</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># draw velocity vectors as arrows with components (u,v) at</span>
            <span class="c"># points (x,y):</span>
            <span class="k">if</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">*</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;xy&#39;</span><span class="p">:</span>
                        <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="n">newaxis</span><span class="p">,:]</span><span class="o">*</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">[:,</span><span class="n">newaxis</span><span class="p">]</span><span class="o">*</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="o">*</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;xy&#39;</span><span class="p">:</span>
                        <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[:,</span><span class="n">newaxis</span><span class="p">]</span><span class="o">*</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="n">newaxis</span><span class="p">,:]</span><span class="o">*</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">)),</span>
                      <span class="s">&#39;with&#39;</span><span class="p">:</span> <span class="n">withstring</span><span class="p">}</span>
            <span class="n">data</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">arrayconverter</span><span class="p">(</span><span class="n">ravel</span><span class="p">(</span><span class="n">x</span><span class="p">)),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">ravel</span><span class="p">(</span><span class="n">y</span><span class="p">)),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">ravel</span><span class="p">(</span><span class="n">u</span><span class="p">)),</span>
                                <span class="n">arrayconverter</span><span class="p">(</span><span class="n">ravel</span><span class="p">(</span><span class="n">v</span><span class="p">)),</span>
                                <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span>

    <span class="k">def</span> <span class="nf">_add_streams</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding streams&quot;</span>
        <span class="c"># grid components:</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="c"># vector components:</span>
        <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;udata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;wdata&#39;</span><span class="p">)</span>
        <span class="c"># starting positions for streams:</span>
        <span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;startx&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;starty&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;startz&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;tubes&#39;</span><span class="p">):</span>
            <span class="c"># draw stream tubes from vector data (u,v,w) at points (x,y,z)</span>
            <span class="n">n</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;n&#39;</span><span class="p">)</span> <span class="c"># no points along the circumference of the tube</span>
            <span class="n">scale</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;tubescale&#39;</span><span class="p">)</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ribbons&#39;</span><span class="p">):</span>
            <span class="c"># draw stream ribbons from vector data (u,v,w) at points (x,y,z)</span>
            <span class="n">width</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ribbonwidth&#39;</span><span class="p">)</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">z</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">w</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># draw stream lines from vector data (u,v,w) at points (x,y,z)</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># draw stream lines from vector data (u,v) at points (x,y)</span>
                <span class="k">pass</span>
            <span class="k">pass</span>

        <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Currently no support for &#39;</span><span class="si">%s</span><span class="s">&#39; in the Gnuplot backend.&quot;</span> <span class="o">%</span> \
              <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;function&#39;</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_add_isosurface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a isosurface&quot;</span>
        <span class="c"># grid components:</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">)</span>  <span class="c"># volume</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cdata&#39;</span><span class="p">)</span>  <span class="c"># pseudocolor data</span>
        <span class="n">isovalue</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;isovalue&#39;</span><span class="p">)</span>

        <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Currently no support for &#39;</span><span class="si">%s</span><span class="s">&#39; in the Gnuplot backend.&quot;</span> <span class="o">%</span> \
              <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;function&#39;</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_add_slices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding slices in a volume&quot;</span>
        <span class="c"># grid components:</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">)</span>  <span class="c"># volume</span>

        <span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;slices&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">sz</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c"># sx, sy, and sz defines a surface</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># sx, sy, and sz is either numbers or vectors with numbers</span>
            <span class="k">pass</span>

        <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Currently no support for &#39;</span><span class="si">%s</span><span class="s">&#39; in the Gnuplot backend.&quot;</span> <span class="o">%</span> \
              <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;function&#39;</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_add_contourslices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding contours in slice planes&quot;</span>
        <span class="c"># grid components:</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">)</span>  <span class="c"># volume</span>

        <span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;slices&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">sz</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c"># sx, sy, and sz defines a surface</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># sx, sy, and sz is either numbers or vectors with numbers</span>
            <span class="k">pass</span>

        <span class="n">cvector</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cvector&#39;</span><span class="p">)</span>
        <span class="n">clevels</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clevels&#39;</span><span class="p">)</span>  <span class="c"># number of contour levels per plane</span>
        <span class="k">if</span> <span class="n">cvector</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># the contour levels are chosen automatically</span>
            <span class="c">#cvector =</span>
            <span class="k">pass</span>

        <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Currently no support for &#39;</span><span class="si">%s</span><span class="s">&#39; in the Gnuplot backend.&quot;</span> <span class="o">%</span> \
              <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;function&#39;</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_figure_size</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fig</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting figure size&quot;</span>
        <span class="n">width</span><span class="p">,</span> <span class="n">height</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;size&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">width</span> <span class="ow">and</span> <span class="n">height</span><span class="p">:</span>
            <span class="c"># set figure width and height</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size </span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">width</span><span class="p">,</span><span class="n">height</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># use the default width and height in plotting package</span>
            <span class="k">pass</span>

<div class="viewcode-block" id="GnuplotBackend.figure"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.figure">[docs]</a>    <span class="k">def</span> <span class="nf">figure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="c"># Extension of BaseClass.figure:</span>
        <span class="c"># add a plotting package figure instance as fig._g and create a</span>
        <span class="c"># link to it as self._g</span>
        <span class="n">fig</span> <span class="o">=</span> <span class="n">BaseClass</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">fig</span><span class="o">.</span><span class="n">_g</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="c"># create plotting package figure and save figure instance</span>
            <span class="c"># as fig._g</span>
            <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
                <span class="n">name</span> <span class="o">=</span> <span class="s">&#39;Fig &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;number&#39;</span><span class="p">))</span>
                <span class="k">print</span> <span class="s">&quot;creating figure </span><span class="si">%s</span><span class="s"> in backend&quot;</span> <span class="o">%</span> <span class="n">name</span>
            <span class="c"># Do not force persist. Instead let the user decide whether to</span>
            <span class="c"># persist a plot through Gnuplot.GnuplotOpts.prefer_persist or</span>
            <span class="c"># the prefer_persist option in the gnuplot section of</span>
            <span class="c"># scitools.cfg.</span>
            <span class="c">#fig._g = Gnuplot.Gnuplot(persist=1)</span>
            <span class="n">fig</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Gnuplot</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">_g</span>  <span class="c"># link for faster access</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_texts</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c"># storage of text calls (dict for set)</span>
        <span class="k">return</span> <span class="n">fig</span>
</div>
    <span class="k">def</span> <span class="nf">_replot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Replot all axes and all plotitems in the backend.&quot;&quot;&quot;</span>
        <span class="c"># NOTE: only the current figure (gcf) is redrawn.</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Doing replot in backend&quot;</span>

        <span class="n">fig</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gcf</span><span class="p">()</span>
        <span class="c"># reset the plotting package instance in fig._g now if needed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
        <span class="c">#self._g(&#39;set size 1.0, 1.0&#39;)</span>
        <span class="c">#self._g(&#39;set origin 0.0, 0.0&#39;)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset multiplot&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set datafile missing &quot;nan&quot;&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_set_figure_size</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;axes&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="c"># multiple axes (subplot)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set multiplot&#39;</span><span class="p">)</span>
        <span class="n">nrows</span><span class="p">,</span> <span class="n">ncolumns</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;axshape&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">axnr</span><span class="p">,</span> <span class="n">ax</span> <span class="ow">in</span> <span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;axes&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">gdata</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_use_splot</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="k">if</span> <span class="n">nrows</span> <span class="o">!=</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">ncolumns</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                <span class="c"># create axes in tiled position</span>
                <span class="c"># this is subplot(nrows,ncolumns,axnr)</span>
                <span class="n">viewport</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;viewport&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">viewport</span><span class="p">:</span>
                    <span class="n">viewport</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
                <span class="n">origin</span> <span class="o">=</span> <span class="n">viewport</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span>
                <span class="n">size</span> <span class="o">=</span> <span class="mi">1</span><span class="o">/</span><span class="n">ncolumns</span><span class="p">,</span> <span class="mi">1</span><span class="o">/</span><span class="n">nrows</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set origin </span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set size </span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">size</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">size</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
            <span class="n">loc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loc_syntax</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set key &#39;</span> <span class="o">+</span> <span class="n">loc</span><span class="p">)</span>
            <span class="n">plotitems</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;plotitems&#39;</span><span class="p">)</span>
            <span class="n">plotitems</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cmpPlotProperties</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">plotitems</span><span class="p">:</span>
                <span class="n">func</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;function&#39;</span><span class="p">)</span> <span class="c"># function that produced this item</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Line</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">func</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;fill&#39;</span><span class="p">:</span>  <span class="c"># fill and fill3</span>
                        <span class="n">gdata</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_add_filled_line</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">gdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_add_line</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">func</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;plot3&#39;</span><span class="p">,</span> <span class="s">&#39;fill3&#39;</span><span class="p">]:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_use_splot</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Bars</span><span class="p">):</span>
                    <span class="n">shading</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;shading&#39;</span><span class="p">)</span>
                    <span class="n">gdata</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_add_bar_graph</span><span class="p">(</span><span class="n">item</span><span class="p">,</span><span class="n">shading</span><span class="o">=</span><span class="n">shading</span><span class="p">))</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Surface</span><span class="p">):</span>
                    <span class="n">gdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_add_surface</span><span class="p">(</span><span class="n">item</span><span class="p">,</span>
                                                   <span class="n">shading</span><span class="o">=</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;shading&#39;</span><span class="p">)))</span>
                    <span class="n">contours</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;contours&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">contours</span><span class="p">:</span>
                        <span class="c"># the current item is produced by meshc or surfc</span>
                        <span class="c"># and we should therefore add contours at the</span>
                        <span class="c"># bottom:</span>
                        <span class="n">gdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_add_contours</span><span class="p">(</span><span class="n">contours</span><span class="p">,</span>
                                                        <span class="n">placement</span><span class="o">=</span><span class="s">&#39;bottom&#39;</span><span class="p">))</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_use_splot</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Contours</span><span class="p">):</span>
                    <span class="n">gdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_add_contours</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset surface&#39;</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_use_splot</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">VelocityVectors</span><span class="p">):</span>
                    <span class="n">gdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_add_vectors</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Streams</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_add_streams</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Volume</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">func</span> <span class="o">==</span> <span class="s">&#39;isosurface&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_add_isosurface</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">func</span> <span class="o">==</span> <span class="s">&#39;slice_&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_add_slices</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">func</span> <span class="o">==</span> <span class="s">&#39;contourslice&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_add_contourslices</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                <span class="n">legend</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">legend</span><span class="p">:</span>
                    <span class="c"># add legend to plot</span>
                    <span class="k">pass</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">_set_axis_props</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">gdata</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_use_splot</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">splot</span><span class="p">(</span><span class="n">gdata</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">gdata</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">gdata</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">gdata</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">replot</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

            <span class="c"># Gnuplot may give thread error for many plot items,</span>
            <span class="c"># let it wait a bit when there are many curves in a plot</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">plotitems</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">6</span><span class="p">:</span>
                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.3</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span> <span class="o">==</span> <span class="s">&#39;win32&#39;</span><span class="p">:</span>
            <span class="c"># Since os.mkfifo is not available on the Windows platform, we</span>
            <span class="c"># store a reference to the gnuplot data so that the temporary</span>
            <span class="c"># files won&#39;t get deleted too early. This should fix the problem</span>
            <span class="c"># with 0 byte images created with hardcopy on Windows. Use the</span>
            <span class="c"># cleanup method to remove the references and free up the memory.</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_gdata</span>
            <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_gdata</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">gdata</span><span class="p">)</span>

        <span class="c"># Display texts (adds texts to latest axes, implying that this</span>
        <span class="c"># does not work well with subplots):</span>
        <span class="k">for</span> <span class="n">args</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_texts</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;show&#39;</span><span class="p">):</span>
            <span class="c"># display plot on the screen</span>
            <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">Dumping plot data to screen</span><span class="se">\n</span><span class="s">&quot;</span>
                <span class="n">debug</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_loc_syntax</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Change from (Matplotlib-inspired) syntax of loc</span>
<span class="sd">        specification of legends to Gnuplot &quot;key&quot; syntax.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">loc</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend_loc&#39;</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">loc</span> <span class="o">=</span> <span class="s">&#39;best&#39;</span>

        <span class="n">mpl2gp</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;upper right&#39;</span><span class="p">:</span> <span class="s">&#39;right top&#39;</span><span class="p">,</span>
            <span class="s">&#39;upper left&#39;</span><span class="p">:</span> <span class="s">&#39;left top&#39;</span><span class="p">,</span>
            <span class="s">&#39;lower left&#39;</span><span class="p">:</span> <span class="s">&#39;left bottom&#39;</span><span class="p">,</span>
            <span class="s">&#39;lower right&#39;</span><span class="p">:</span> <span class="s">&#39;right bottom&#39;</span><span class="p">,</span>
            <span class="s">&#39;center left&#39;</span><span class="p">:</span> <span class="s">&#39;left center&#39;</span><span class="p">,</span>
            <span class="s">&#39;center right&#39;</span><span class="p">:</span> <span class="s">&#39;right center&#39;</span><span class="p">,</span>
            <span class="s">&#39;lower center&#39;</span><span class="p">:</span> <span class="s">&#39;center bottom&#39;</span><span class="p">,</span>
            <span class="s">&#39;upper center&#39;</span><span class="p">:</span> <span class="s">&#39;center top&#39;</span><span class="p">,</span>
            <span class="s">&#39;best&#39;</span><span class="p">:</span> <span class="s">&#39;right top&#39;</span><span class="p">,</span> <span class="c"># default</span>
            <span class="s">&#39;right&#39;</span><span class="p">:</span> <span class="s">&#39;right top&#39;</span><span class="p">,</span>
            <span class="s">&#39;center&#39;</span><span class="p">:</span> <span class="s">&#39;center center&#39;</span><span class="p">}</span>
        <span class="n">loc</span> <span class="o">=</span> <span class="n">mpl2gp</span><span class="p">[</span><span class="n">loc</span><span class="p">]</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">fancybox</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend_fancybox&#39;</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">fancybox</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="k">if</span> <span class="n">fancybox</span><span class="p">:</span>
            <span class="n">loc</span> <span class="o">=</span> <span class="n">loc</span> <span class="o">+</span> <span class="s">&#39; box&#39;</span>
        <span class="k">return</span> <span class="n">loc</span>


<div class="viewcode-block" id="GnuplotBackend.cleanup"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.cleanup">[docs]</a>    <span class="k">def</span> <span class="nf">cleanup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Clean up data.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gdata</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.text"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.text">[docs]</a>    <span class="k">def</span> <span class="nf">text</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span>
             <span class="n">fontname</span><span class="o">=</span><span class="n">Axis</span><span class="o">.</span><span class="n">_local_prop</span><span class="p">[</span><span class="s">&#39;fontname&#39;</span><span class="p">],</span>
             <span class="n">fontsize</span><span class="o">=</span><span class="n">Axis</span><span class="o">.</span><span class="n">_local_prop</span><span class="p">[</span><span class="s">&#39;fontsize&#39;</span><span class="p">]):</span>
        <span class="sd">&quot;&quot;&quot;Write text at position (x,y) in a curveplot.&quot;&quot;&quot;</span>
        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;set label &quot;</span><span class="si">%s</span><span class="s">&quot; at </span><span class="si">%f</span><span class="s">,</span><span class="si">%f</span><span class="s"> font &quot;</span><span class="si">%s</span><span class="s">,</span><span class="si">%d</span><span class="s">&quot;&#39;</span> <span class="o">%</span> \
            <span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">fontname</span><span class="p">,</span> <span class="n">fontsize</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">refresh</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_texts</span><span class="p">[(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="n">fontname</span><span class="p">,</span> <span class="n">fontsize</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">None</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.hardcopy"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.hardcopy">[docs]</a>    <span class="k">def</span> <span class="nf">hardcopy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Currently supported extensions in Gnuplot backend:</span>

<span class="sd">          &#39;.ps&#39;  (PostScript)</span>
<span class="sd">          &#39;.eps&#39; (Encapsualted PostScript)</span>
<span class="sd">          &#39;.png&#39; (Portable Network Graphics)</span>
<span class="sd">          &#39;.pdf&#39; (Portable Document Format)</span>

<span class="sd">        Optional arguments for PostScript output:</span>

<span class="sd">        ===========    =====================================================</span>
<span class="sd">        Argument       Description</span>
<span class="sd">        ===========    =====================================================</span>
<span class="sd">        color          If True, create a plot with colors. If False</span>
<span class="sd">                       (default),  create a plot in black and white.</span>
<span class="sd">        enhanced       If True (default), enable enhanced text mode features</span>
<span class="sd">                       like subscripts, superscripts, and mixed fonts.</span>
<span class="sd">        orientation    Set orientation to &#39;portrait&#39; or &#39;landscape&#39;. Default</span>
<span class="sd">                       is to leave this unchanged. This option has no effect</span>
<span class="sd">                       on EPS or PDF output.</span>
<span class="sd">        solid          If True, force lines to become solid (i.e., not</span>
<span class="sd">                       dashed). Default is False.</span>
<span class="sd">        fontname       Set the font to be used for titles, labels, etc.</span>
<span class="sd">                       Must be a valid PostScript font or an oblique version</span>
<span class="sd">                       of the Symbol font (called &quot;Symbol-Oblique&quot;) which is</span>
<span class="sd">                       useful for mathematics. Default font is &quot;Helvetica&quot;.</span>
<span class="sd">        fontsize       Set the size of the font in points. Default is 20 for</span>
<span class="sd">                       for PostScript output and 8 for PDF output.</span>
<span class="sd">        ===========    =====================================================</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Hardcopy to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">filename</span>

        <span class="n">ext2term</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;.ps&#39;</span><span class="p">:</span> <span class="s">&#39;postscript&#39;</span><span class="p">,</span>
                    <span class="s">&#39;.eps&#39;</span><span class="p">:</span> <span class="s">&#39;postscript&#39;</span><span class="p">,</span>
                    <span class="s">&#39;.png&#39;</span><span class="p">:</span> <span class="s">&#39;png&#39;</span><span class="p">}</span>

        <span class="c"># check if we have a PDF terminal</span>
        <span class="k">if</span> <span class="n">_check_terminal</span><span class="p">(</span><span class="s">&#39;pdfcairo&#39;</span><span class="p">):</span>
            <span class="n">ext2term</span><span class="p">[</span><span class="s">&#39;.pdf&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;pdfcairo&#39;</span>
            <span class="c"># teach Gnuplot.py about the pdfcairo terminal</span>
            <span class="c"># FIXME: This might need some tweaking. Or is this even needed?</span>
            <span class="n">Gnuplot</span><span class="o">.</span><span class="n">termdefs</span><span class="o">.</span><span class="n">terminal_opts</span><span class="p">[</span><span class="s">&#39;pdfcairo&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
                <span class="n">Gnuplot</span><span class="o">.</span><span class="n">termdefs</span><span class="o">.</span><span class="n">KeywordOrBooleanArg</span><span class="p">(</span>
                    <span class="n">options</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;landscape&#39;</span><span class="p">,</span> <span class="s">&#39;portrait&#39;</span><span class="p">,</span> <span class="s">&#39;eps&#39;</span><span class="p">,</span> <span class="s">&#39;default&#39;</span><span class="p">],</span>
                    <span class="n">argname</span><span class="o">=</span><span class="s">&#39;mode&#39;</span><span class="p">,</span>
                    <span class="p">),</span>
                <span class="n">Gnuplot</span><span class="o">.</span><span class="n">termdefs</span><span class="o">.</span><span class="n">KeywordOrBooleanArg</span><span class="p">(</span><span class="n">options</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;color&#39;</span><span class="p">,</span> <span class="s">&#39;monochrome&#39;</span><span class="p">]),</span>
                <span class="n">Gnuplot</span><span class="o">.</span><span class="n">termdefs</span><span class="o">.</span><span class="n">KeywordOrBooleanArg</span><span class="p">(</span><span class="n">options</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;solid&#39;</span><span class="p">,</span> <span class="s">&#39;dashed&#39;</span><span class="p">]),</span>
                <span class="n">Gnuplot</span><span class="o">.</span><span class="n">termdefs</span><span class="o">.</span><span class="n">KeywordOrBooleanArg</span><span class="p">(</span>
                    <span class="n">options</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;defaultplex&#39;</span><span class="p">,</span> <span class="s">&#39;simplex&#39;</span><span class="p">,</span> <span class="s">&#39;duplex&#39;</span><span class="p">],</span>
                    <span class="n">argname</span><span class="o">=</span><span class="s">&#39;duplexing&#39;</span><span class="p">,</span>
                    <span class="p">),</span>
                <span class="n">Gnuplot</span><span class="o">.</span><span class="n">termdefs</span><span class="o">.</span><span class="n">StringArg</span><span class="p">(</span><span class="n">argname</span><span class="o">=</span><span class="s">&#39;fontname&#39;</span><span class="p">),</span>
                <span class="n">Gnuplot</span><span class="o">.</span><span class="n">termdefs</span><span class="o">.</span><span class="n">BareStringArg</span><span class="p">(</span><span class="n">argname</span><span class="o">=</span><span class="s">&#39;fontsize&#39;</span><span class="p">),</span>
                <span class="p">]</span>
        <span class="k">elif</span> <span class="n">_check_terminal</span><span class="p">(</span><span class="s">&#39;pdf&#39;</span><span class="p">):</span>
            <span class="n">ext2term</span><span class="p">[</span><span class="s">&#39;.pdf&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;pdf&#39;</span>

        <span class="n">basename</span><span class="p">,</span> <span class="n">ext</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">ext</span><span class="p">:</span>
            <span class="c"># no extension given, assume .ps:</span>
            <span class="n">ext</span> <span class="o">=</span> <span class="s">&#39;.ps&#39;</span>
            <span class="n">filename</span> <span class="o">+=</span> <span class="n">ext</span>
        <span class="k">elif</span> <span class="n">ext</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ext2term</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;hardcopy: extension must be </span><span class="si">%s</span><span class="s">, not &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> \
                             <span class="p">(</span><span class="n">ext2term</span><span class="o">.</span><span class="n">keys</span><span class="p">(),</span> <span class="n">ext</span><span class="p">))</span>
        <span class="n">terminal</span> <span class="o">=</span> <span class="n">ext2term</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ext</span><span class="p">,</span> <span class="s">&#39;postscript&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;color&#39;</span><span class="p">)</span>
        <span class="n">enhanced</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;enhanced&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
        <span class="n">orientation</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;orientation&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        <span class="n">solid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;solid&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
        <span class="n">fontname</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;fontname&#39;</span><span class="p">,</span> <span class="s">&#39;Helvetica&#39;</span><span class="p">)</span>
        <span class="n">keyw</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;filename&#39;</span><span class="p">:</span> <span class="n">filename</span><span class="p">,</span> <span class="s">&#39;terminal&#39;</span><span class="p">:</span> <span class="n">terminal</span><span class="p">}</span>

        <span class="c"># Create a new Gnuplot instance only for now</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Gnuplot</span><span class="p">()</span>
        <span class="n">setterm</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;set&#39;</span><span class="p">,</span> <span class="s">&#39;terminal&#39;</span><span class="p">,</span> <span class="n">terminal</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">terminal</span> <span class="o">==</span> <span class="s">&#39;postscript&#39;</span><span class="p">:</span>
            <span class="n">fontsize</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;fontsize&#39;</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
            <span class="n">keyw</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">&#39;color&#39;</span><span class="p">:</span> <span class="n">color</span><span class="p">,</span> <span class="s">&#39;enhanced&#39;</span><span class="p">:</span> <span class="n">enhanced</span><span class="p">,</span> <span class="s">&#39;solid&#39;</span><span class="p">:</span> <span class="n">solid</span><span class="p">,</span>
                         <span class="s">&#39;fontname&#39;</span><span class="p">:</span> <span class="n">fontname</span><span class="p">,</span> <span class="s">&#39;fontsize&#39;</span><span class="p">:</span> <span class="n">fontsize</span><span class="p">})</span>
            <span class="k">if</span> <span class="n">ext</span> <span class="o">==</span> <span class="s">&#39;.eps&#39;</span><span class="p">:</span>
                <span class="n">keyw</span><span class="p">[</span><span class="s">&#39;mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;eps&#39;</span>
                <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;eps&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">orientation</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;landscape&#39;</span><span class="p">,</span> <span class="s">&#39;portrait&#39;</span><span class="p">]:</span>
                    <span class="n">keyw</span><span class="p">[</span><span class="s">&#39;mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">orientation</span>
                    <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">orientation</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">enhanced</span> <span class="ow">and</span> <span class="s">&#39;enhanced&#39;</span> <span class="ow">or</span> <span class="s">&#39;noenhanced&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">color</span> <span class="ow">and</span> <span class="s">&#39;color&#39;</span> <span class="ow">or</span> <span class="s">&#39;monochrome&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">solid</span> <span class="ow">and</span> <span class="s">&#39;solid&#39;</span> <span class="ow">or</span> <span class="s">&#39;dashed&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39; dashlength 5 linewidth 3&#39;</span><span class="p">)</span>  <span class="c"># look best</span>
            <span class="c">#setterm.append(&#39; dashlength 5 linewidth 4&#39;)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;&quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">fontname</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">fontsize</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_doing_PS</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">elif</span> <span class="n">terminal</span> <span class="o">==</span> <span class="s">&#39;pdf&#39;</span><span class="p">:</span>
            <span class="n">fontsize</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;fontsize&#39;</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">color</span> <span class="ow">and</span> <span class="s">&#39;color&#39;</span> <span class="ow">or</span> <span class="s">&#39;monochrome&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">enhanced</span> <span class="ow">and</span> <span class="s">&#39;enhanced&#39;</span> <span class="ow">or</span> <span class="s">&#39;noenhanced&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;font &quot;</span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">fontname</span><span class="p">,</span> <span class="n">fontsize</span><span class="p">))</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;linewidth 4&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">solid</span> <span class="ow">and</span> <span class="s">&#39;solid&#39;</span> <span class="ow">or</span> <span class="s">&#39;dashed&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;dl 3&#39;</span><span class="p">)</span>  <span class="c"># dashlength</span>
            <span class="c"># FIXME: Should self._doing_PS be True or False in this case?</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_doing_PS</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">elif</span> <span class="n">terminal</span> <span class="o">==</span> <span class="s">&#39;pdfcairo&#39;</span><span class="p">:</span>
            <span class="n">fontsize</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;fontsize&#39;</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">enhanced</span> <span class="ow">and</span> <span class="s">&#39;enhanced&#39;</span> <span class="ow">or</span> <span class="s">&#39;noenhanced&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">color</span> <span class="ow">and</span> <span class="s">&#39;color&#39;</span> <span class="ow">or</span> <span class="s">&#39;mono&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">solid</span> <span class="ow">and</span> <span class="s">&#39;solid&#39;</span> <span class="ow">or</span> <span class="s">&#39;dashed&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;font &quot;</span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">fontname</span><span class="p">,</span> <span class="n">fontsize</span><span class="p">))</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;linewidth 4&#39;</span><span class="p">)</span>
            <span class="n">setterm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;dashlength 3&#39;</span><span class="p">)</span>
            <span class="c"># FIXME: Should self._doing_PS be True or False in this case?</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_doing_PS</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">elif</span> <span class="n">terminal</span> <span class="o">==</span> <span class="s">&#39;png&#39;</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">setterm</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set output &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">filename</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_replot</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">gcf</span><span class="p">()</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;axes&#39;</span><span class="p">))</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="c"># Need to call hardcopy in Gnuplot.py to avoid ending up with</span>
            <span class="c"># a PostScript file with multiple pages:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">hardcopy</span><span class="p">(</span><span class="o">**</span><span class="n">keyw</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;quit&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gcf</span><span class="p">()</span><span class="o">.</span><span class="n">_g</span>  <span class="c"># set self._g to the correct instance again</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_doing_PS</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;interactive&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;show&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_replot</span><span class="p">()</span>

</div>
<div class="viewcode-block" id="GnuplotBackend.hardcopy_old"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.hardcopy_old">[docs]</a>    <span class="k">def</span> <span class="nf">hardcopy_old</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Currently supported extensions in Gnuplot backend:</span>

<span class="sd">          &#39;.ps&#39;  (PostScript)</span>
<span class="sd">          &#39;.eps&#39; (Encapsualted PostScript)</span>
<span class="sd">          &#39;.png&#39; (Portable Network Graphics)</span>

<span class="sd">        Optional arguments:</span>

<span class="sd">          color       -- True (colors) or False (black and white).</span>
<span class="sd">          fontname    -- default is Helvetica.</span>
<span class="sd">          fontsize    -- default is 16.</span>
<span class="sd">          orientation -- &#39;portrait&#39; or &#39;landscape&#39; (default). Only available</span>
<span class="sd">                         for PostScript output.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Hardcopy to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">filename</span>

        <span class="n">ext2term</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;.ps&#39;</span><span class="p">:</span> <span class="s">&#39;postscript&#39;</span><span class="p">,</span>
                    <span class="s">&#39;.eps&#39;</span><span class="p">:</span> <span class="s">&#39;postscript&#39;</span><span class="p">,</span>
                    <span class="s">&#39;.png&#39;</span><span class="p">:</span> <span class="s">&#39;png&#39;</span><span class="p">}</span>
        <span class="n">basename</span><span class="p">,</span> <span class="n">ext</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">ext</span><span class="p">:</span>
            <span class="c"># no extension given, assume .ps:</span>
            <span class="n">ext</span> <span class="o">=</span> <span class="s">&#39;.ps&#39;</span>
            <span class="n">filename</span> <span class="o">+=</span> <span class="n">ext</span>
        <span class="k">elif</span> <span class="n">ext</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ext2term</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;hardcopy: extension must be </span><span class="si">%s</span><span class="s">, not &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> \
                             <span class="p">(</span><span class="n">ext2term</span><span class="o">.</span><span class="n">keys</span><span class="p">(),</span> <span class="n">ext</span><span class="p">))</span>
        <span class="n">terminal</span> <span class="o">=</span> <span class="n">ext2term</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ext</span><span class="p">,</span> <span class="s">&#39;postscript&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">fontname</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;fontname&#39;</span><span class="p">,</span> <span class="s">&#39;Helvetica&#39;</span><span class="p">)</span>
        <span class="n">fontsize</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;fontsize&#39;</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>
        <span class="n">orientation</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;orientation&#39;</span><span class="p">,</span> <span class="s">&#39;landscape&#39;</span><span class="p">)</span>
        <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;color&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;unset multiplot&#39;</span><span class="p">)</span> <span class="c"># is this necessary?</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;show&#39;</span><span class="p">):</span> <span class="c"># OK to display to screen</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_replot</span><span class="p">()</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;filename&#39;</span><span class="p">:</span> <span class="n">filename</span><span class="p">,</span> <span class="s">&#39;terminal&#39;</span><span class="p">:</span> <span class="n">terminal</span><span class="p">}</span>
            <span class="k">if</span> <span class="n">terminal</span> <span class="o">==</span> <span class="s">&#39;postscript&#39;</span><span class="p">:</span>
                <span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">&#39;color&#39;</span><span class="p">:</span> <span class="n">color</span><span class="p">,</span> <span class="s">&#39;enhanced&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>
                               <span class="s">&#39;fontname&#39;</span><span class="p">:</span> <span class="n">fontname</span><span class="p">,</span> <span class="s">&#39;fontsize&#39;</span><span class="p">:</span> <span class="n">fontsize</span><span class="p">})</span>
                <span class="k">if</span> <span class="n">ext</span> <span class="o">==</span> <span class="s">&#39;.eps&#39;</span><span class="p">:</span>
                    <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;eps&#39;</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">orientation</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">hardcopy</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span> <span class="c"># Manually set terminal and don&#39;t show windows</span>
            <span class="k">if</span> <span class="n">color</span><span class="p">:</span>
                <span class="n">colortype</span> <span class="o">=</span> <span class="s">&#39;color&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">colortype</span> <span class="o">=</span> <span class="s">&#39;monochrome&#39;</span>

            <span class="c"># Create a new Gnuplot instance only for now</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Gnuplot</span><span class="p">()</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;filename&#39;</span><span class="p">:</span> <span class="n">filename</span><span class="p">,</span> <span class="s">&#39;terminal&#39;</span><span class="p">:</span> <span class="n">terminal</span><span class="p">}</span>
            <span class="k">if</span> <span class="n">terminal</span> <span class="o">==</span> <span class="s">&#39;postscript&#39;</span><span class="p">:</span>
                <span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">&#39;color&#39;</span><span class="p">:</span> <span class="n">color</span><span class="p">,</span> <span class="s">&#39;enhanced&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>
                               <span class="s">&#39;fontname&#39;</span><span class="p">:</span> <span class="n">fontname</span><span class="p">,</span> <span class="s">&#39;fontsize&#39;</span><span class="p">:</span> <span class="n">fontsize</span><span class="p">})</span>
                <span class="k">if</span> <span class="n">ext</span> <span class="o">==</span> <span class="s">&#39;.eps&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set term postscript eps </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">colortype</span><span class="p">)</span>
                    <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;eps&#39;</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set term postscript </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                            <span class="p">(</span><span class="n">orientation</span><span class="p">,</span> <span class="n">colortype</span><span class="p">))</span>
                    <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">orientation</span>
            <span class="k">elif</span> <span class="n">terminal</span> <span class="o">==</span> <span class="s">&#39;png&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set term png&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;set output &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="n">filename</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_replot</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">hardcopy</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;quit&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gcf</span><span class="p">()</span><span class="o">.</span><span class="n">_g</span> <span class="c"># set _g to the correct instance again</span>

    <span class="c"># reimplement methods like clf, closefig, closefigs</span></div>
<div class="viewcode-block" id="GnuplotBackend.clf"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.clf">[docs]</a>    <span class="k">def</span> <span class="nf">clf</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Clear current figure.&quot;&quot;&quot;</span>
        <span class="n">BaseClass</span><span class="o">.</span><span class="n">clf</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span> <span class="c"># reset gnuplot instance</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.closefig"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.closefig">[docs]</a>    <span class="k">def</span> <span class="nf">closefig</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Close figure window.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">num</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">num</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_figs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">pass</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.closefigs"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.closefigs">[docs]</a>    <span class="k">def</span> <span class="nf">closefigs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Close figure windows and stop gnuplot.&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_figs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_figs</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">_g</span><span class="p">(</span><span class="s">&#39;quit&#39;</span><span class="p">)</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_g</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_figs</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span><span class="n">Figure</span><span class="p">()}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_figs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Gnuplot</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_figs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">_g</span>

    <span class="c"># Colormaps:</span></div>
<div class="viewcode-block" id="GnuplotBackend.hsv"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.hsv">[docs]</a>    <span class="k">def</span> <span class="nf">hsv</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;rgbformulae 3,2,2&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model HSV maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.hot"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.hot">[docs]</a>    <span class="k">def</span> <span class="nf">hot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;rgbformulae 21,22,23&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.gray"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.gray">[docs]</a>    <span class="k">def</span> <span class="nf">gray</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;black&quot;, 1 &quot;white&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.bone"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.bone">[docs]</a>    <span class="k">def</span> <span class="nf">bone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;black&quot;, 4 &quot;light-blue&quot;, 5 &quot;white&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.copper"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.copper">[docs]</a>    <span class="k">def</span> <span class="nf">copper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;black&quot;, 1 &quot;coral&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.pink"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.pink">[docs]</a>    <span class="k">def</span> <span class="nf">pink</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;black&quot;, 1 &quot;pink&quot;, 8 &quot;pink&quot;, 10 &quot;white&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.white"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.white">[docs]</a>    <span class="k">def</span> <span class="nf">white</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;white&quot;, 1 &quot;white&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
<span class="c">##         if m &gt; 0:</span>
<span class="c">##             cmap = ones((m, 3), float)</span>
<span class="c">##         else:</span>
<span class="c">##             cmap = []</span>
<span class="c">##         return cmap</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.flag"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.flag">[docs]</a>    <span class="k">def</span> <span class="nf">flag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">colors</span> <span class="o">=</span> <span class="s">&quot;red,white,blue,black&quot;</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
        <span class="n">j</span><span class="o">=</span><span class="n">k</span><span class="o">=</span><span class="mi">0</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (&#39;</span>
        <span class="k">while</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="mi">16</span><span class="p">:</span>
            <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">while</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">colors</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span>
                <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>  <span class="n">i</span> <span class="o">+=</span> <span class="mi">2</span>
                <span class="n">c</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;, </span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;, &#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">2</span><span class="p">],</span><span class="n">j</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">k</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">c</span><span class="p">[:</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span><span class="o">+</span><span class="s">&#39;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.lines"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.lines">[docs]</a>    <span class="k">def</span> <span class="nf">lines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="c"># NOTE: not finished</span>
        <span class="n">colors</span> <span class="o">=</span> <span class="s">&quot;blue,green,red,cyan,magenta,yellow,black&quot;</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
        <span class="n">j</span><span class="o">=</span><span class="n">k</span><span class="o">=</span><span class="mi">0</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (&#39;</span>
        <span class="k">while</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="mi">9</span><span class="p">:</span>
            <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">c</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">j</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">while</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">colors</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span>
                <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>  <span class="n">i</span> <span class="o">+=</span> <span class="mi">2</span>
                <span class="n">c</span> <span class="o">+=</span> <span class="s">&#39;, </span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;, </span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">j</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span><span class="n">j</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="n">k</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">c</span> <span class="o">+=</span> <span class="s">&#39;, &#39;</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">c</span><span class="p">[:</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span><span class="o">+</span><span class="s">&#39;)&#39;</span>
        <span class="c">#print c</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.colorcube"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.colorcube">[docs]</a>    <span class="k">def</span> <span class="nf">colorcube</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">colors</span> <span class="o">=</span> <span class="s">&quot;white,black,gray0,gray10,grey20,grey30,gray40,gray50,&quot;</span>\
                 <span class="s">&quot;gray60,grey70,grey80,gray90,grey100,grey,light-grey,&quot;</span>\
                 <span class="s">&quot;dark-grey,red,light-red,dark-red,yellow,light-yellow,&quot;</span>\
                 <span class="s">&quot;dark-yellow,green,light-green,dark-green,spring-green,&quot;</span>\
                 <span class="s">&quot;forest-green,sea-green,blue,light-blue,dark-blue,&quot;</span>\
                 <span class="s">&quot;midnight-blue,navy,medium-blue,royalblue,skyblue,cyan,&quot;</span>\
                 <span class="s">&quot;light-cyan,dark-cyan,magenta,light-magenta,dark-magenta,&quot;</span>\
                 <span class="s">&quot;turquoise,light-turquoise,dark-turquoise,pink,light-pink,&quot;</span>\
                 <span class="s">&quot;dark-pink,coral,light-coral,orange-red,salmon,light-salmon,&quot;</span>\
                 <span class="s">&quot;dark-salmon,aquamarine,khaki,dark-khaki,gold,goldenrod,&quot;</span>\
                 <span class="s">&quot;light-goldenrod,dark-goldenrod,beige,brown,orange,&quot;</span>\
                 <span class="s">&quot;dark-orange,violet,dark-violet,plum,purple&quot;</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
        <span class="n">i</span><span class="o">=</span><span class="n">j</span><span class="o">=</span><span class="mi">0</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (</span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">while</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">colors</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span>
            <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>  <span class="n">i</span> <span class="o">+=</span> <span class="mi">2</span>
            <span class="n">c</span> <span class="o">+=</span> <span class="s">&#39;, </span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;, </span><span class="si">%d</span><span class="s"> &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">j</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span><span class="n">j</span><span class="p">,</span><span class="n">colors</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
        <span class="n">c</span> <span class="o">+=</span> <span class="s">&#39;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.vga"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.vga">[docs]</a>    <span class="k">def</span> <span class="nf">vga</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">None</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.jet"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.jet">[docs]</a>    <span class="k">def</span> <span class="nf">jet</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;blue&quot;, 3 &quot;cyan&quot;, 4 &quot;green&quot;, 5 &quot;yellow&quot;, &#39;</span>\
            <span class="s">&#39;8 &quot;red&quot;, 10 &quot;black&quot;)&#39;</span> <span class="c"># stop at red (remove black)</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.prism"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.prism">[docs]</a>    <span class="k">def</span> <span class="nf">prism</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">None</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.cool"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.cool">[docs]</a>    <span class="k">def</span> <span class="nf">cool</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;cyan&quot;, 1 &quot;magenta&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.autumn"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.autumn">[docs]</a>    <span class="k">def</span> <span class="nf">autumn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;red&quot;, 1 &quot;yellow&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.spring"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.spring">[docs]</a>    <span class="k">def</span> <span class="nf">spring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;magenta&quot;, 1 &quot;yellow&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.winter"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.winter">[docs]</a>    <span class="k">def</span> <span class="nf">winter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;blue&quot;, 1 &quot;spring-green&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="GnuplotBackend.summer"><a class="viewcode-back" href="../../../gnuplot_.html#scitools.easyviz.gnuplot_.GnuplotBackend.summer">[docs]</a>    <span class="k">def</span> <span class="nf">summer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">c</span> <span class="o">=</span> <span class="s">&#39;defined (0 &quot;green&quot;, 1 &quot;yellow&quot;)&#39;</span>
        <span class="k">return</span> <span class="s">&#39;set palette model RGB maxcolors </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>


    <span class="c"># Now we add the doc string from the methods in BaseClass to the</span>
    <span class="c"># methods that are reimplemented in this backend:</span></div>
    <span class="k">for</span> <span class="n">cmd</span> <span class="ow">in</span> <span class="n">BaseClass</span><span class="o">.</span><span class="n">_matlab_like_cmds</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="s">&#39;__&#39;</span> <span class="ow">in</span> <span class="n">cmd</span> <span class="ow">and</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">BaseClass</span><span class="p">,</span> <span class="n">cmd</span><span class="p">):</span>
            <span class="n">m1</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="s">&#39;BaseClass.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">cmd</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">m2</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">cmd</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">NameError</span><span class="p">:</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">m1</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">!=</span> <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                        <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
                    <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">=</span> <span class="n">m1</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">+</span> <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span>

</div>
<span class="n">plt</span> <span class="o">=</span> <span class="n">GnuplotBackend</span><span class="p">()</span>  <span class="c"># create backend instance</span>
<span class="n">use</span><span class="p">(</span><span class="n">plt</span><span class="p">,</span> <span class="nb">globals</span><span class="p">())</span>     <span class="c"># export public namespace of plt to globals()</span>
<span class="n">backend</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">__file__</span><span class="p">))[</span><span class="mi">0</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/scitools_logo.jpg" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, H. P. Langtangen, J. Ring, ++.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
    </div>
  </body>
</html>